// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import Client from '@api/base/api/ScheduleRecordApi'

import OneClass from '@api/base/model/ScheduleRecordReq'

const CLIENT = CORE.grpcCLIENT(Client)

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 单项 —————————————————————————————— //

  validOne(one) {
    return one.id
  },
  async getOne({ id }, TIP = '查询交接详情') {
    const DTO = CORE.grpcDTO(OneClass, { recordId: [id] })
    const resp = await CORE.grpc(TIP, CLIENT, 'queryScheduleRecordDetail', DTO)
    return resp.content || {}
  },
  transOne(obj) {
    const file = obj.file || []
    obj.imageList = file.filter((item) => item.fileType === 1)
    obj.audioList = file.filter((item) => item.fileType === 2)

    obj.event.forEach((item) => {
      if (item.type === 3) item.contentValue = CORE.dict(CORE.DICT.YES, +item.contentValue)
    })

    // 合并子列表
    obj.children = [...(obj.state || []), ...(obj.record || []), ...(obj.event || [])]

    return obj
  },
}
